import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'



Vue.config.productionTip = false
Vue.prototype.$axios  = axios

//全局过滤器
// 字符串 <--> Date对象
// 字符串 <--> 时间戳
// 时间戳 <--> Date对象
Vue.filter('timeFilter', (time)=>{

  let parse = function(n){
    return n >= 10 ? n : `0${n}`
  }

  let date = new Date(time)
  let Y = date.getFullYear()
  let M = parse(date.getMonth() + 1)
  let D = parse(date.getDate())
  let h = parse(date.getHours())
  let m = parse(date.getMinutes())
  let s = parse(date.getSeconds())

  return `${Y}-${M}-${D} ${h}:${m}:${s}`
})

//时间的文字描述
Vue.filter('timeStrFilter', function(time){
  let date = new Date(time)
  let old = date.getTime()//获取历史的时间戳
  let now = Date.now() //现在的时间戳
  let t = now - old //时间量(毫秒)
  let m = 1000 * 60 //分钟的单位量
  let h = m * 60 //小时的单位量
  let day = h * 24 //天的单位量
  let month = day * 30 //月的单位量
  let year = month * 12 //年的单位量

  let str
  if(t <= m){
    str = '刚刚'
  }else if(t > m && t <= m * 3){
    str = '1分钟前'
  }else if(t > m * 3 && t <= m * 5){
    str = '3分钟前'
  }else if(t > m * 5 && t <= m * 10){
    str = '5分钟前'
  }else if(t > m * 10 && t <= m * 30){
    str = '10分钟前'
  }else if(t > m * 30 && t <= h){
    str = '半小时前'
  }else if(t > h && t <= h * 3){
    str = '1小时前'
  }else if(t > h * 3 && t <= h * 5){
    str = '3小时前'
  }else if(t > h * 5 && t <= h * 12){
    str = '5小时前'
  }else if(t > h * 12 && t <= day){
    str = '半天前'
  }else if(t > day && t <= day * 3){
    str = '1天前'
  }else if(t > day * 3 && t <= day * 5){
    str = '3天前'
  }else if(t > day * 5 && t <= day * 15){
    str = '5天前'
  }else if(t > day * 15 && t < month){
    str = '半个月前'
  }else {
    str = '很久以前'
  }

  return str
})





new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
